import { DD_SYSTEM } from '@/constants/api-pre';
import { request } from '@/service/request';

/** log login */
export type LogOperate = Api.Common.CommonRecord<{
  traceId: string;
  userId: string;
  userType: number;
  nickname: string;
  applicationName: string;
  javaMethod: string;
  requestMethod: string;
  requestParams: string;
  requestBody: string;
  responseBody: string;
  requestUrl: string;
  userIp: string;
  userAgent: string;
  operateModule: string;
  operateName: string;
  operateType: number | null;
  beginTime: Date | null;
  endTime: Date | null;
  duration: number | null;
  resultCode: string;
  resultMsg: string;
}>;

/** log login search params */
export type LogOperateSearchParams = CommonType.RecordNullable<
  Pick<LogOperate, 'userId' | 'userType' | 'applicationName' | 'duration' | 'resultCode' | 'operateType' | 'nickname'> &
    Api.Common.CommonSearchParams & {
      beginTime: null;
    }
>;
/** log login list */
export type LogOperateList = Api.Common.PaginatingQueryRecord<LogOperate>;

/** fetch log login list */
export function fetchGetLogOperateList(params?: LogOperateSearchParams) {
  return request<LogOperateList>({
    url: `${DD_SYSTEM}/operate-log/page`,
    method: 'get',
    params
  });
}
